package com.hjq.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

import java.util.Arrays;

@Slf4j
@Component
@Aspect
public class MyAspect6{
    @Before("execution(* com.hjq.service.impl.DeptServiceImpl.*(..))")
    public void before(JoinPoint joinPoint){
        log.info("MyAspect5 -> before ...");
        // 获取目标对象
        Object target = joinPoint.getTarget();
        log.info("获取目标对象：{}",target);
        //获取目标类
        String name = joinPoint.getTarget().getClass().getName();
        log.info("获取目标类:{}",name);
        //获取目标方法
        String methodName = joinPoint.getSignature().getName();
        log.info("获取目标方法:{}",methodName);
        //获取目标方法运行参数
        Object[] args = joinPoint.getArgs();
        log.info("获取目标方法运行参数,{}", Arrays.toString(args));
    }

    @Around("execution(* com.hjq.service.impl.DeptServiceImpl.*(..))")
    public Object around(ProceedingJoinPoint joinPoint) throws Throwable {
        log.info("MyAspect5 -> around ...");
        Object proceed = joinPoint.proceed();
        return proceed;
    }
}